{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ultralytics YOLOv8.1.34 🚀 Python-3.9.19 torch-1.12.1+cu113 CUDA:0 (NVIDIA A100-SXM4-80GB, 81038MiB)\n",
      "WARNING ⚠️ Upgrade to torch>=2.0.0 for deterministic training.\n",
      "\u001b[34m\u001b[1mengine/trainer: \u001b[0mtask=detect, mode=train, model=yolov8n.pt, data=coco128.yaml, epochs=3, time=None, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train2, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs/detect/train2\n",
      "\n",
      "                   from  n    params  module                                       arguments                     \n",
      "  0                  -1  1       464  ultralytics.nn.modules.conv.Conv             [3, 16, 3, 2]                 \n",
      "  1                  -1  1      4672  ultralytics.nn.modules.conv.Conv             [16, 32, 3, 2]                \n",
      "  2                  -1  1      7360  ultralytics.nn.modules.block.C2f             [32, 32, 1, True]             \n",
      "  3                  -1  1     18560  ultralytics.nn.modules.conv.Conv             [32, 64, 3, 2]                \n",
      "  4                  -1  2     49664  ultralytics.nn.modules.block.C2f             [64, 64, 2, True]             \n",
      "  5                  -1  1     73984  ultralytics.nn.modules.conv.Conv             [64, 128, 3, 2]               \n",
      "  6                  -1  2    197632  ultralytics.nn.modules.block.C2f             [128, 128, 2, True]           \n",
      "  7                  -1  1    295424  ultralytics.nn.modules.conv.Conv             [128, 256, 3, 2]              \n",
      "  8                  -1  1    460288  ultralytics.nn.modules.block.C2f             [256, 256, 1, True]           \n",
      "  9                  -1  1    164608  ultralytics.nn.modules.block.SPPF            [256, 256, 5]                 \n",
      " 10                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          \n",
      " 11             [-1, 6]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           \n",
      " 12                  -1  1    148224  ultralytics.nn.modules.block.C2f             [384, 128, 1]                 \n",
      " 13                  -1  1         0  torch.nn.modules.upsampling.Upsample         [None, 2, 'nearest']          \n",
      " 14             [-1, 4]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           \n",
      " 15                  -1  1     37248  ultralytics.nn.modules.block.C2f             [192, 64, 1]                  \n",
      " 16                  -1  1     36992  ultralytics.nn.modules.conv.Conv             [64, 64, 3, 2]                \n",
      " 17            [-1, 12]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           \n",
      " 18                  -1  1    123648  ultralytics.nn.modules.block.C2f             [192, 128, 1]                 \n",
      " 19                  -1  1    147712  ultralytics.nn.modules.conv.Conv             [128, 128, 3, 2]              \n",
      " 20             [-1, 9]  1         0  ultralytics.nn.modules.conv.Concat           [1]                           \n",
      " 21                  -1  1    493056  ultralytics.nn.modules.block.C2f             [384, 256, 1]                 \n",
      " 22        [15, 18, 21]  1    897664  ultralytics.nn.modules.head.Detect           [80, [64, 128, 256]]          \n",
      "Model summary: 225 layers, 3157200 parameters, 3157184 gradients, 8.9 GFLOPs\n",
      "\n",
      "Transferred 355/355 items from pretrained weights\n",
      "Freezing layer 'model.22.dfl.conv.weight'\n",
      "\u001b[34m\u001b[1mAMP: \u001b[0mrunning Automatic Mixed Precision (AMP) checks with YOLOv8n...\n",
      "\u001b[34m\u001b[1mAMP: \u001b[0mchecks passed ✅\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[34m\u001b[1mtrain: \u001b[0mScanning /home/ubuntu/fx/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]\n",
      "\u001b[34m\u001b[1mval: \u001b[0mScanning /home/ubuntu/fx/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Plotting labels to runs/detect/train2/labels.jpg... \n",
      "\u001b[34m\u001b[1moptimizer:\u001b[0m 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... \n",
      "\u001b[34m\u001b[1moptimizer:\u001b[0m AdamW(lr=0.000119, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0)\n",
      "Image sizes 640 train, 640 val\n",
      "Using 8 dataloader workers\n",
      "Logging results to \u001b[1mruns/detect/train2\u001b[0m\n",
      "Starting training for 3 epochs...\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "        1/3      2.81G      1.215       1.67       1.27        217        640: 100%|██████████| 8/8 [00:01<00:00,  4.78it/s]\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:01<00:00,  2.27it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   all        128        929       0.65      0.515      0.611      0.452\n",
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "        2/3      2.52G      1.202      1.443      1.231        218        640: 100%|██████████| 8/8 [00:00<00:00,  8.58it/s]\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:00<00:00,  8.50it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   all        128        929      0.654      0.544      0.622      0.465\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "        3/3      2.81G      1.164      1.398      1.256        215        640: 100%|██████████| 8/8 [00:00<00:00,  9.90it/s]\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:00<00:00,  8.93it/s]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   all        128        929      0.655      0.549      0.625      0.466\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "3 epochs completed in 0.002 hours.\n",
      "Optimizer stripped from runs/detect/train2/weights/last.pt, 6.5MB\n",
      "Optimizer stripped from runs/detect/train2/weights/best.pt, 6.5MB\n",
      "\n",
      "Validating runs/detect/train2/weights/best.pt...\n",
      "Ultralytics YOLOv8.1.34 🚀 Python-3.9.19 torch-1.12.1+cu113 CUDA:0 (NVIDIA A100-SXM4-80GB, 81038MiB)\n",
      "Model summary (fused): 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 4/4 [00:01<00:00,  3.12it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   all        128        929      0.654       0.54      0.625      0.465\n",
      "                person        128        254      0.799      0.675      0.767      0.544\n",
      "               bicycle        128          6      0.494      0.333      0.317      0.252\n",
      "                   car        128         46      0.786      0.217      0.279      0.172\n",
      "            motorcycle        128          5      0.709        0.8      0.898      0.707\n",
      "              airplane        128          6      0.832      0.828      0.903      0.697\n",
      "                   bus        128          7      0.554      0.714      0.727      0.678\n",
      "                 train        128          3      0.554      0.667      0.764      0.628\n",
      "                 truck        128         12      0.986      0.417      0.484      0.288\n",
      "                  boat        128          6      0.279      0.167      0.369      0.241\n",
      "         traffic light        128         14      0.749      0.214      0.205       0.14\n",
      "             stop sign        128          2      0.939          1      0.995      0.706\n",
      "                 bench        128          9      0.828      0.536      0.634      0.398\n",
      "                  bird        128         16      0.897       0.75       0.89       0.54\n",
      "                   cat        128          4      0.907          1      0.995      0.818\n",
      "                   dog        128          9      0.599      0.778      0.824      0.616\n",
      "                 horse        128          2      0.548          1      0.995      0.557\n",
      "              elephant        128         17      0.795      0.765      0.876      0.656\n",
      "                  bear        128          1      0.621          1      0.995      0.995\n",
      "                 zebra        128          4      0.856          1      0.995      0.965\n",
      "               giraffe        128          9       0.86          1      0.973      0.725\n",
      "              backpack        128          6      0.619      0.333      0.393      0.237\n",
      "              umbrella        128         18      0.767      0.549      0.695      0.471\n",
      "               handbag        128         19      0.658      0.105      0.263      0.144\n",
      "                   tie        128          7      0.711      0.706      0.643      0.475\n",
      "              suitcase        128          4       0.66          1      0.828      0.604\n",
      "               frisbee        128          5      0.666        0.8      0.732      0.639\n",
      "                  skis        128          1      0.483          1      0.995      0.497\n",
      "             snowboard        128          7      0.785      0.714      0.718      0.492\n",
      "           sports ball        128          6      0.697      0.395      0.503      0.291\n",
      "                  kite        128         10       0.83       0.49      0.583        0.2\n",
      "          baseball bat        128          4      0.387       0.25      0.331      0.166\n",
      "        baseball glove        128          7      0.668      0.429       0.43      0.295\n",
      "            skateboard        128          5      0.755        0.6        0.6      0.424\n",
      "         tennis racket        128          7      0.541       0.51      0.466      0.311\n",
      "                bottle        128         18      0.468      0.333      0.357       0.21\n",
      "            wine glass        128         16      0.638      0.375      0.545      0.339\n",
      "                   cup        128         36      0.547       0.25      0.402      0.289\n",
      "                  fork        128          6      0.601      0.167      0.241      0.188\n",
      "                 knife        128         16      0.554      0.625      0.607      0.365\n",
      "                 spoon        128         22      0.603      0.182      0.305      0.164\n",
      "                  bowl        128         28      0.717      0.643      0.648      0.508\n",
      "                banana        128          1          0          0      0.166     0.0566\n",
      "              sandwich        128          2     0.0897      0.135      0.497      0.497\n",
      "                orange        128          4          1      0.326      0.995      0.662\n",
      "              broccoli        128         11      0.501      0.182      0.255      0.205\n",
      "                carrot        128         24      0.716       0.63      0.696      0.455\n",
      "               hot dog        128          2      0.637      0.911      0.828      0.796\n",
      "                 pizza        128          5      0.773          1      0.995      0.869\n",
      "                 donut        128         14      0.653          1      0.911      0.833\n",
      "                  cake        128          4      0.719          1      0.995       0.88\n",
      "                 chair        128         35      0.467      0.543       0.47      0.267\n",
      "                 couch        128          6      0.598      0.496      0.635      0.493\n",
      "          potted plant        128         14      0.785      0.643      0.742      0.495\n",
      "                   bed        128          3      0.775      0.667       0.83       0.66\n",
      "          dining table        128         13      0.476      0.615      0.513      0.411\n",
      "                toilet        128          2       0.63        0.5      0.828      0.763\n",
      "                    tv        128          2      0.396        0.5      0.695      0.656\n",
      "                laptop        128          3          1          0      0.626       0.55\n",
      "                 mouse        128          2          1          0      0.057     0.0057\n",
      "                remote        128          8      0.838        0.5      0.573      0.497\n",
      "            cell phone        128          8          0          0     0.0544     0.0348\n",
      "             microwave        128          3      0.481      0.667       0.83      0.683\n",
      "                  oven        128          5      0.433        0.4      0.339       0.27\n",
      "                  sink        128          6      0.357      0.167      0.261      0.171\n",
      "          refrigerator        128          5      0.672        0.4      0.672      0.516\n",
      "                  book        128         29       0.64      0.124      0.404      0.197\n",
      "                 clock        128          9      0.784       0.81      0.894       0.77\n",
      "                  vase        128          2      0.308          1      0.828      0.745\n",
      "              scissors        128          1          1          0      0.199     0.0597\n",
      "            teddy bear        128         21          1      0.396      0.652      0.409\n",
      "            toothbrush        128          5      0.774        0.4      0.743      0.488\n",
      "Speed: 1.4ms preprocess, 0.5ms inference, 0.0ms loss, 0.9ms postprocess per image\n",
      "Results saved to \u001b[1mruns/detect/train2\u001b[0m\n",
      "Ultralytics YOLOv8.1.34 🚀 Python-3.9.19 torch-1.12.1+cu113 CUDA:0 (NVIDIA A100-SXM4-80GB, 81038MiB)\n",
      "Model summary (fused): 168 layers, 3151904 parameters, 0 gradients, 8.7 GFLOPs\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[34m\u001b[1mval: \u001b[0mScanning /home/ubuntu/fx/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s]\n",
      "                 Class     Images  Instances      Box(P          R      mAP50  mAP50-95): 100%|██████████| 8/8 [00:01<00:00,  4.38it/s]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                   all        128        929      0.662      0.538      0.629      0.467\n",
      "                person        128        254      0.811      0.673       0.77      0.542\n",
      "               bicycle        128          6      0.498      0.333      0.317      0.251\n",
      "                   car        128         46      0.798      0.217      0.279      0.173\n",
      "            motorcycle        128          5      0.719        0.8      0.898      0.707\n",
      "              airplane        128          6      0.831      0.822      0.903      0.697\n",
      "                   bus        128          7      0.583      0.714      0.727      0.678\n",
      "                 train        128          3      0.556      0.667      0.764      0.628\n",
      "                 truck        128         12          1      0.417      0.485      0.289\n",
      "                  boat        128          6       0.24      0.167      0.339      0.146\n",
      "         traffic light        128         14      0.745       0.21      0.205       0.14\n",
      "             stop sign        128          2      0.949          1      0.995      0.707\n",
      "                 bench        128          9      0.826      0.531      0.634      0.398\n",
      "                  bird        128         16      0.907       0.75      0.882       0.52\n",
      "                   cat        128          4      0.875          1      0.995      0.866\n",
      "                   dog        128          9      0.649      0.778      0.824      0.621\n",
      "                 horse        128          2      0.552          1      0.995      0.557\n",
      "              elephant        128         17      0.851      0.765      0.881      0.655\n",
      "                  bear        128          1      0.625          1      0.995      0.995\n",
      "                 zebra        128          4      0.857          1      0.995      0.965\n",
      "               giraffe        128          9      0.745      0.977      0.943      0.736\n",
      "              backpack        128          6      0.627      0.333       0.45      0.276\n",
      "              umbrella        128         18      0.751        0.5      0.681      0.463\n",
      "               handbag        128         19      0.738      0.105      0.262      0.145\n",
      "                   tie        128          7      0.709        0.7      0.643      0.475\n",
      "              suitcase        128          4      0.663      0.986      0.828      0.604\n",
      "               frisbee        128          5      0.626      0.677      0.733       0.64\n",
      "                  skis        128          1      0.489          1      0.995      0.497\n",
      "             snowboard        128          7      0.787      0.714      0.718       0.49\n",
      "           sports ball        128          6      0.691      0.333      0.545       0.28\n",
      "                  kite        128         10      0.826      0.479      0.583      0.211\n",
      "          baseball bat        128          4      0.397       0.25      0.348      0.199\n",
      "        baseball glove        128          7      0.673      0.429       0.43      0.316\n",
      "            skateboard        128          5      0.826        0.6        0.6      0.452\n",
      "         tennis racket        128          7      0.738      0.407      0.528       0.35\n",
      "                bottle        128         18       0.48      0.333      0.378      0.216\n",
      "            wine glass        128         16      0.648      0.375      0.541      0.334\n",
      "                   cup        128         36       0.57      0.258      0.395      0.289\n",
      "                  fork        128          6      0.595      0.167      0.236        0.2\n",
      "                 knife        128         16      0.579      0.625      0.599      0.371\n",
      "                 spoon        128         22       0.61      0.182      0.311      0.171\n",
      "                  bowl        128         28       0.75      0.642      0.646      0.491\n",
      "                banana        128          1          0          0      0.166     0.0562\n",
      "              sandwich        128          2      0.262      0.393      0.497      0.497\n",
      "                orange        128          4          1      0.328      0.995      0.666\n",
      "              broccoli        128         11      0.506      0.182      0.257      0.205\n",
      "                carrot        128         24      0.707      0.602      0.696      0.451\n",
      "               hot dog        128          2      0.635      0.906      0.828      0.796\n",
      "                 pizza        128          5      0.853          1      0.995      0.843\n",
      "                 donut        128         14      0.645          1      0.926      0.843\n",
      "                  cake        128          4      0.724          1      0.995       0.88\n",
      "                 chair        128         35      0.483      0.543      0.457      0.251\n",
      "                 couch        128          6      0.549        0.5      0.711      0.563\n",
      "          potted plant        128         14       0.68      0.608      0.707      0.474\n",
      "                   bed        128          3      0.685      0.667      0.913      0.689\n",
      "          dining table        128         13      0.493      0.538      0.505      0.399\n",
      "                toilet        128          2      0.634        0.5      0.828      0.796\n",
      "                    tv        128          2      0.409        0.5      0.745      0.696\n",
      "                laptop        128          3          1          0      0.598       0.48\n",
      "                 mouse        128          2          1          0     0.0568    0.00568\n",
      "                remote        128          8      0.828        0.5       0.59      0.504\n",
      "            cell phone        128          8          0          0     0.0581     0.0378\n",
      "             microwave        128          3      0.499      0.667       0.83      0.683\n",
      "                  oven        128          5      0.441        0.4      0.339       0.27\n",
      "                  sink        128          6      0.365      0.167      0.254      0.177\n",
      "          refrigerator        128          5      0.675        0.4      0.639      0.494\n",
      "                  book        128         29      0.636      0.122      0.408      0.212\n",
      "                 clock        128          9      0.783      0.805      0.896      0.751\n",
      "                  vase        128          2      0.379          1      0.828      0.745\n",
      "              scissors        128          1          1          0      0.249     0.0746\n",
      "            teddy bear        128         21          1      0.373      0.648      0.417\n",
      "            toothbrush        128          5      0.743        0.6      0.755      0.454\n",
      "Speed: 1.2ms preprocess, 2.5ms inference, 0.0ms loss, 1.9ms postprocess per image\n",
      "Results saved to \u001b[1mruns/detect/train22\u001b[0m\n",
      "\n",
      "Downloading https://ultralytics.com/images/bus.jpg to 'bus.jpg'...\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4a9c8ab4ef3c45a3baecb70270497e5a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "  0%|          | 0.00/476k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "image 1/1 /home/ubuntu/shaocong.xu/exp/ultralytics/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 11.4ms\n",
      "Speed: 2.8ms preprocess, 11.4ms inference, 1.5ms postprocess per image at shape (1, 3, 640, 480)\n",
      "Ultralytics YOLOv8.1.34 🚀 Python-3.9.19 torch-1.12.1+cu113 CPU (Intel Xeon 2.20GHz)\n",
      "\n",
      "\u001b[34m\u001b[1mPyTorch:\u001b[0m starting from 'runs/detect/train2/weights/best.pt' with input shape (1, 3, 640, 640) BCHW and output shape(s) (1, 84, 8400) (6.2 MB)\n",
      "\u001b[31m\u001b[1mrequirements:\u001b[0m Ultralytics requirement ['onnx>=1.12.0'] not found, attempting AutoUpdate...\n",
      "Collecting onnx>=1.12.0\n",
      "  Downloading onnx-1.16.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (16 kB)\n",
      "Requirement already satisfied: numpy>=1.20 in /home/ubuntu/miniconda3/envs/ultralytics/lib/python3.9/site-packages (from onnx>=1.12.0) (1.26.4)\n",
      "Collecting protobuf>=3.20.2 (from onnx>=1.12.0)\n",
      "  Downloading protobuf-5.26.0-cp37-abi3-manylinux2014_x86_64.whl.metadata (592 bytes)\n",
      "Downloading onnx-1.16.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (15.9 MB)\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.9/15.9 MB\u001b[0m \u001b[31m214.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hDownloading protobuf-5.26.0-cp37-abi3-manylinux2014_x86_64.whl (302 kB)\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m302.8/302.8 kB\u001b[0m \u001b[31m308.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hInstalling collected packages: protobuf, onnx\n",
      "Successfully installed onnx-1.16.0 protobuf-5.26.0\n",
      "\n",
      "\u001b[31m\u001b[1mrequirements:\u001b[0m AutoUpdate success ✅ 4.9s, installed 1 package: ['onnx>=1.12.0']\n",
      "\u001b[31m\u001b[1mrequirements:\u001b[0m ⚠️ \u001b[1mRestart runtime or rerun command for updates to take effect\u001b[0m\n",
      "\n",
      "\n",
      "\u001b[34m\u001b[1mONNX:\u001b[0m starting export with onnx 1.16.0 opset 10...\n",
      "\u001b[34m\u001b[1mONNX:\u001b[0m export success ✅ 7.2s, saved as 'runs/detect/train2/weights/best.onnx' (12.2 MB)\n",
      "\n",
      "Export complete (8.8s)\n",
      "Results saved to \u001b[1m/home/ubuntu/shaocong.xu/exp/ultralytics/runs/detect/train2/weights\u001b[0m\n",
      "Predict:         yolo predict task=detect model=runs/detect/train2/weights/best.onnx imgsz=640  \n",
      "Validate:        yolo val task=detect model=runs/detect/train2/weights/best.onnx imgsz=640 data=/home/ubuntu/shaocong.xu/exp/ultralytics/ultralytics/cfg/datasets/coco128.yaml  \n",
      "Visualize:       https://netron.app\n"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "import os \n",
    "\n",
    "os.chdir('/home/ubuntu/shaocong.xu/exp/ultralytics')\n",
    "\n",
    "from ultralytics import YOLO\n",
    "\n",
    "# Create a new YOLO model from scratch\n",
    "model = YOLO('yolov8n.yaml')\n",
    "\n",
    "# Load a pretrained YOLO model (recommended for training)\n",
    "model = YOLO('yolov8n.pt')\n",
    "\n",
    "# Train the model using the 'coco128.yaml' dataset for 3 epochs\n",
    "results = model.train(data='coco128.yaml', epochs=3)\n",
    "\n",
    "# Evaluate the model's performance on the validation set\n",
    "results = model.val()\n",
    "\n",
    "# Perform object detection on an image using the model\n",
    "results = model('https://ultralytics.com/images/bus.jpg')\n",
    "\n",
    "# Export the model to ONNX format\n",
    "success = model.export(format='onnx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'settings_version': '0.0.4', 'datasets_dir': '/home/ubuntu/fx/datasets', 'weights_dir': 'weights', 'runs_dir': 'runs', 'uuid': '5b071c7d1a5f5ac21d204ad0f4f2d231b79eb2c4469e9aa16c453a05ec7e876f', 'sync': True, 'api_key': '', 'openai_api_key': '', 'clearml': True, 'comet': True, 'dvc': True, 'hub': True, 'mlflow': True, 'neptune': True, 'raytune': True, 'tensorboard': True, 'wandb': True}\n"
     ]
    }
   ],
   "source": [
    "from ultralytics import settings\n",
    "\n",
    "# View all settings\n",
    "print(settings)\n",
    "\n",
    "# Return a specific setting\n",
    "value = settings['runs_dir']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ultralytics import settings\n",
    "\n",
    "# Update a setting\n",
    "settings.update({'runs_dir': '/path/to/runs'})\n",
    "\n",
    "# Update multiple settings\n",
    "settings.update({'runs_dir': '/path/to/runs', 'tensorboard': False})\n",
    "\n",
    "# Reset settings to default values\n",
    "settings.reset()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/ubuntu/shaocong.xu/exp/ultralytics/runs\n"
     ]
    }
   ],
   "source": [
    "# print(settings['runs_dir'])\n",
    "print(settings)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "ultralytics",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
